package com.proyecto.core.vista.echo.componentes;

import java.util.EventListener;
import java.util.ResourceBundle;

import nextapp.echo2.app.Color;
import nextapp.echo2.app.WindowPane;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.ContentPane;
import nextapp.echo2.app.ApplicationInstance;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.Button;
import nextapp.echo2.app.ResourceImageReference;
import nextapp.echo2.extras.app.ColorSelect;
import nextapp.echo2.app.layout.RowLayoutData;
import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.layout.ColumnLayoutData;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;

@SuppressWarnings("serial")
public class WPColores extends WindowPane {

	private ResourceBundle resourceBundle;

	String colorcitoSelect = "";
	Color colorcito;
	Integer colorRGB;
	
	private ColorSelect clrPaletaColores;

	/**
	 * Creates a new <code>WPColores</code>.
	 */
	public WPColores() {
		super();

		// Add design-time configured components.
		initComponents();
		this.setModal(true);
		this.setResizable(false);
		this.setTitle("Paleta de Colores");
	}

	public void addActionListener(ActionListener l) {
        getEventListenerList().addListener(ActionListener.class, l);
    }
	
	private void capturaColorAction(ActionEvent e) {
		//TODO Implement.
		
		//colorcito = clrPaletaColores.getColor();
		colorRGB = clrPaletaColores.getColor().getRgb();
		//System.out.println("colorcito::: " + colorcito);
		//colorcitoSelect = colorcito.toString();
		//System.out.println("colorcito.toString::: " + colorcito.toString());

		//System.out.println("colorcitoSelect::: " + colorcitoSelect);
		System.out.println("colorRGB::: " + colorRGB);
		getParent().remove(WPColores.this);

	    EventListener listener = getEventListenerList().getListeners(ActionListener.class)[0];
	    ActionEvent outgoingEvent = new ActionEvent(this, colorRGB.toString());
	    ((ActionListener) listener).actionPerformed(outgoingEvent);
	    
	}

	/**
	 * Configures initial state of component.
	 * WARNING: AUTO-GENERATED METHOD.
	 * Contents will be overwritten.
	 */
	private void initComponents() {
		resourceBundle = ResourceBundle.getBundle(
				"com.proyecto.core.vista.echo.resource.localization.etiquetas",
				ApplicationInstance.getActive().getLocale());
		this.setWidth(new Extent(250, Extent.PX));
		this.setHeight(new Extent(280, Extent.PX));
		this.setStyleName("DefaultWPFechaCalendario");
		ContentPane contentPane1 = new ContentPane();
		add(contentPane1);
		Column column1 = new Column();
		contentPane1.add(column1);
		Row row1 = new Row();
		row1.setStyleName("2OpenLabs.Row.SeparadorInicial");
		column1.add(row1);
		Row row2 = new Row();
		ColumnLayoutData row2LayoutData = new ColumnLayoutData();
		row2LayoutData.setAlignment(new Alignment(Alignment.CENTER,
				Alignment.DEFAULT));
		row2.setLayoutData(row2LayoutData);
		column1.add(row2);
		clrPaletaColores = new ColorSelect();
		RowLayoutData clrPaletaColoresLayoutData = new RowLayoutData();
		clrPaletaColoresLayoutData.setInsets(new Insets(
				new Extent(0, Extent.PX), new Extent(15, Extent.PX),
				new Extent(0, Extent.PX), new Extent(0, Extent.PX)));
		clrPaletaColoresLayoutData.setAlignment(new Alignment(Alignment.CENTER,
				Alignment.DEFAULT));
		clrPaletaColores.setLayoutData(clrPaletaColoresLayoutData);
		row2.add(clrPaletaColores);
		Row row3 = new Row();
		row3.setStyleName("2OpenLabs.Row.BotoneraInterna");
		column1.add(row3);
		Button button1 = new Button();
		button1.setText(resourceBundle
				.getString("CoreVista.base.RowBotonera.Aceptar"));
		ResourceImageReference imageReference1 = new ResourceImageReference(
				"/com/proyecto/core/vista/echo/resource/image/icon/general/Iconos/accept.png");
		button1.setIcon(imageReference1);
		button1.setStyleName("2OpenLabs.Button.Transaccion");
		button1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				capturaColorAction(e);
			}
		});
		row3.add(button1);
	}
}
